

import { Notification, Message, Loading } from 'element-ui'

import { Commit, Dispatch } from 'vuex';
import { get, defaultsDeep, cloneDeep } from 'lodash'

import { getReviewList, commitReviewResult } from '@/api/review'



export interface State {

}

const state: State = {
    reviewSearch: {
        drawingNumber: '',
        reviewProcess: '',
        state: '',
        page: 1,
        pageSize: 20
    },
    processList: [],
    numberQualified: 0,
    numberRework: 0,
    numberWasteIndustrial: 0,
    numberWasteMaterial: 0
};

const getters = {};

const mutations = {
    SET_REVIEW_SEARCH(state: any, payload: any) {
        state.reviewSearch = payload
    },
    SET_FIVE_DATA(state: any, payload: any) {
        state.processList = payload
    },
    SET_QUALIFIED(state: any, payload: any) {
        state.numberQualified = payload
    },
    SET_REWORK(state: any, payload: any) {
        state.numberRework = payload
    },
    SET_WASTE_INDUSTRIAL(state: any, payload: any) {
        state.numberWasteIndustrial = payload
    },
    SET_WASTE_MATERIAL(state: any, payload: any) {
        state.numberWasteMaterial = payload
    },

};

const actions = {
    //表单数据更新
    COMMIT_TABLE_fiveDATA({ commit, state }: any) {
        let params = state.reviewSearch


        getReviewList(params).then((resp) => {

            let processList = get(resp, 'processList', [])
            //  console.log('ts'+processList)
            commit('SET_FIVE_DATA', processList)
        })

    },

    //05_14_技术评审查询
    async GET_REVIEW_LIST(
        { state, commit, rootState, dispatch }: any,
        payload: any
    ) {

        let resp = await getReviewList(payload).catch((err: any) => {
            Notification.error(err)
        })

        if (resp) {
            let processList = get(resp, 'data', [])
            commit('SET_FIVE_DATA', processList)
            console.log(resp);
            return true
        }
    },

    //2-17提交技术评审结果
    async COMMIT_REVIEW_RESULT(
        { state, commit, rootState, dispatch }: any,
        payload: any
    ) {

        let resp = await commitReviewResult(payload).catch((err: any) => {
            Notification.error(err)
        })

        if (resp) {
            Message.success('提交成功!')
            console.log(resp);
            //更新表格
            //  dispatch('SET_ADD_NOTICE')
            //更新表格
            //  dispatch('COMMIT_TABLE_fiveDATA')
            return true
        }

    },

}


export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
};